home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MacQForth 1.0 / source / MacQForth Source / 65C02.mops next >
Text File  |  1995-03-29  |  14KB  |  169 lines

  1. \ Section: 65C02 Instructions
  2.  
  3. \ ADC - Add to Accumulator with Carry
  4.   
  5.   \ set processor status flags
  6.   : psADC ( v -- ) 
  7.       >r r FF > if r 100 - rA ! #C set else #C unset then  \ carry
  8.       r 0= if #Z set else #Z unset then    \ zero
  9.       r 7F > if #N set else #N unset then \ negative
  10.       r> 80 and oldA @ 80 and <> if #V set else #V unset then \ overflow
  11.   ; 
  12.   
  13.   : doADC  
  14.      inline{ rA @ dup oldA ! + #C @v + dup rA ! psADC }
  15.   ;   
  16.   
  17.   \ code
  18.   : $69 imm. doADC ; \ immediate
  19.   : $65 zpg. doADC ; \ zero page
  20.   : $75 zpx. doADC ; \ zero page,rX
  21.   : $72 zpi. doADC ; \ zero page indirect
  22.   : $6D abs. doADC ; \ absolute
  23.   : $7D abx. doADC ; \ absolute,rX  
  24.   : $79 aby. doADC ; \ absolute,rY
  25.   : $61 inx. doADC ; \ indirect,rX
  26.   : $71 iny. doADC ; \ indirect,rY
  27.  
  28. \ AND - and Memory with Accumulator
  29.  
  30.   : psAND 
  31.      dup 0= if #Z set else #Z unset then \ zero
  32.      7F > if #N set else #N unset then  ; \ negative
  33.   
  34.   : doAND  inline{ rA @ and dup rA ! psAND } ;
  35.   
  36.   : $29 imm. doAND ; \ immediate
  37.   : $25 zpg. doAND ; \ zero page
  38.   : $32 zpi. doAND ; \ zero page indirect
  39.   : $35 zpx. doAND ; \ zero page,rX
  40.   : $2D abs. doAND ; \ absolute
  41.   : $3D abx. doAND ; \ absolute,rX
  42.   : $39 aby. doAND ; \ absolute,rY
  43.   : $21 inx. doAND ; \ indirect,rX
  44.   : $31 iny. doAND ; \ indirect,rY
  45.  
  46.  
  47. \ ASL - Accumulator Shift Left
  48.  
  49.   : psASL dup FF > if 100 - #C set else #C unset then
  50.       dup 0= if #Z set else #Z unset then
  51.       dup 7F > if #N set else #N unset then
  52.   ;
  53.   
  54.   : $0A rA @  2* psASL rA !  ;      \ accumulator
  55.   : $06 zpg. 2* psASL addr @ $! ; \ zero page
  56.   : $16 zpx. 2* psASL addr @ $! ; \ zero page,rX
  57.   : $0E abs. 2* psASL addr @ $! ; \ absolute
  58.   : $1E abx. 2* psASL addr @ $! ; \ absolute,rX
  59.  
  60.   
  61. \ BCC - Branch on Carry Clear
  62.  
  63.   : $90 imm. #C @ if drop else branch0 then ;
  64.  
  65. \ BCS - Branch on Carry Set
  66.  
  67.   : $B0 imm. #C @ if branch0 else drop then ;
  68.   
  69. \ BEQ - Branch on result Equal to Zero
  70.  
  71.   : $F0 imm. #Z @ if branch0 else drop then ;
  72.   
  73. \ BIT - Test Bits in Memory with Accumulator
  74.  
  75.   : doBIT ( n -- ) \ perform a BIT operation
  76.      dup dup
  77.      80 and 0= if #N unset else #N set then
  78.      40 and 0= if #V unset else #N set then
  79.      rA @ and 0= if #Z set else #Z unset then ;
  80.  
  81.   : $89 imm. rA @ and 0= if #Z set else #Z unset then ;
  82.   : $24 zpg. doBIT ;
  83.   : $34 zpx. doBIT ;
  84.   : $2C abs. doBIT ;
  85.   : $3C abx. doBIT ;
  86.  
  87. \ BMI - Branch on result minus
  88.  
  89.   : $30 imm. #N @ if branch0 else drop then ;
  90.   
  91. \ BNE - Branch on result not equal to zero
  92.  
  93.   : $D0 imm. #Z @ if drop else branch0 then ;
  94.  
  95. \ BPL - Branch on result plus
  96.  
  97.   : $10 imm. #N @ if drop else branch0 then ;
  98.  
  99. \ BRA - Branch relative always
  100.  
  101.   : $80 imm. branch0 ;
  102.   
  103. \ BRK - Break - enters the program whose address is $F7FE lo $F7FF hi
  104.  
  105.   : $00  0F7FE $@ 0F7FF $@ >addr rPC ! ;
  106.   
  107. \ BVC - Branch on overflow clear
  108.  
  109.   : $50 imm. #V @ if drop else branch0 then ;
  110.   
  111. \ BVS - Branch on overflow set
  112.  
  113.   : $70 imm. #V @ if branch0 else drop then ;
  114.   
  115. \ CLC - Clear Carry Flag
  116.  
  117.   : $18 #C unset ;
  118.   
  119. \ CLD - Clear Decimal Flag
  120.  
  121.   : $D8 #D unset ;
  122.   
  123. \ CLI - Clear Interrupt Disable
  124.  
  125.   : $58 #I unset ;
  126.   
  127. \ CLV - Clear overflow flag
  128.  
  129.   : $B8 #V unset ;
  130.   
  131. \ CMP - Compare Memory and Accumulator
  132.  
  133.   : doCMP 
  134.      dup rA @ swap < if #N set #Z unset #C unset drop else
  135.      dup rA @ = if #Z set #C set #N unset drop else
  136.          rA @ swap > if #C set #Z unset #N unset then 
  137.      then then ;
  138.   
  139.   : $C9 imm. doCMP ;
  140.   : $C5 zpg. doCMP ;
  141.   : $D5 zpx. doCMP ;
  142.   : $D2 zpi. doCMP ;
  143.   : $CD abs. doCMP ;
  144.   : $DD abx. doCMP ;
  145.   : $D9 aby. doCMP ;
  146.   : $C1 inx. doCMP ;
  147.   : $D1 iny. doCMP ;
  148.  
  149. \ CPX - Compare Memory and rX
  150.  
  151.   : doCPX 
  152.      dup rX @ swap < if #N set #Z unset #C unset drop else
  153.      dup rX @ = if #Z set #C set #N unset drop else
  154.          rX @ swap > if #C set #Z unset #N unset then 
  155.      then then ;
  156.   
  157.   : $E0 imm. doCPX ;
  158.   : $E4 zpg. doCPX ;
  159.   : $EC abs. doCPX ;
  160.  
  161. \ CPY - Compare Memory and rY
  162.  
  163.   : doCPY 
  164.      dup rY @ swap < if #N set #Z unset #C unset drop else
  165.      dup rY @ = if #Z set #C set #N unset drop else
  166.          rY @ swap > if #C set #Z unset #N unset then 
  167.      then then ;
  168.   
  169.   : $C0 im